﻿<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
'本页面只供文件夹中的页面调用
response.Expires=0
'设置连接数据库参数
dim conn
'连接数据库
set conn=server.CreateObject("adodb.connection")
conn.open "Provider=sqloledb; Server=TUOBEE\SQLEXPRESS; Database=pth; uid=sa; Password=sasasa"
'关闭数据库
Function CloseDatabase
	conn.close
	Set conn=Nothing
End Function
'打开数据库表，查询通用语句
Function GetRecordset(strSQL,intOpenType)
	dim rs
	set rs=server.CreateObject("adodb.recordset")
	
	select case intOpenType
	case 0'只读
	 rs.open strSQL,conn,0,1
	case 1'读写
	 rs.open strSQL,conn,1,3
	case 2'读写
	 rs.open strSQL,conn,1,1 
	end select
	
	set GetRecordset=rs
End Function
'根据ID获得一条记录
Function GetRecodsetWithID(strTable,intID,intOpenType)
	dim strSQL
	strSQL="select * from ["& strTable & "] where ID="&intID&" and [delete]=0"
	set GetRecordsetWithID=GetRecordset(strSQL,intOpenType)
End Function
'根据ID删除一条记录，将delete字段设为真
Function DeleteRecordset(strTable,intID)
	dim rs
	set rs=GetRecodsetWithID(strTable,intID,1)
	rs("delete")=1
	rs.update
	set rs=nothing
End Function
'是否存在符合要求的记录
function IsExistRecordset(strSQL)
	dim rs,SQL
	SQL="Select count(*) as countR "&strSQL
	set rs=GetRecordset(SQL,0)
	if rs("countR").value=0 then
		IsExistRecordset=false
	else IsExistRecordset=true
	end if
	set rs=nothing
end function
'是否登录，将Cookies与数据库进行对比
Function IsLogin()
	dim username,passwd,userIdent,strSQL,rs
	username=Request.Cookies("username")
	passwd=Request.Cookies("passwd")
	userIdent=request.Cookies("userIdent")
	if username<>"" and passwd<>"" and userIdent<>"" then
		strSQL="select count(*) as countR from [user] where userNum='"&username&"' and userPwd='"&passwd&"' and userIdentityID="&userIdent&" and [delete]=0"
		set rs=GetRecordset(strSQL,0)
		if rs("countR")=1 then
			IsLogin=True
		else IsLogin=false
		end if
		rs.close
		set rs=nothing
	else IsLogin=False
	end if
End Function
'根据权限专有名，检测用户权限，需检测的页面有专有名
Function checkIP(strIP)
	dim strSQL,rs
	if IsLogin then
	strSQL="select * from view_checkIP where permissionName='"&strIP&"' and identityID="&Request.Cookies("userIdent")
	set rs=GetRecordset(strSQL,0)
	if not rs.eof and not rs.bof then
		checkIP=True
	else checkIP=false
	end if
	rs.close
	set rs=nothing
	else checkIP=false
	end if
End Function
'设置Cookies
function setCookies(userNum,userPwd,userIdent)
	response.Cookies("username")=userNum
	response.Cookies("passwd")=userPwd
	response.Cookies("RemMe")=0
	response.Cookies("userIdent")=userIdent
end function
'清楚Cookies
function clearCookies()
    response.Cookies("username")=""
	response.Cookies("passwd")=""
	response.Cookies("RemMe")=0
	response.Cookies("userIdent")=0
end function
'生成随机数函数
Function GetRandomizeCode()
 Randomize
 Dim m_strRandArray,m_intRandlen,m_strRandomize,i
 m_strRandArray = Array(0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z")
 m_intRandlen = 16 ''定义随机码的长度
 for i = 1 to m_intRandlen
  m_strRandomize = m_strRandomize & m_strRandArray(Int((21*Rnd)))
 next
 GetRandomizeCode = m_strRandomize
End Function
'显示错误信息，并根据要求跳转
'intMode 0:错误，返回  1:成功,来自评价平台  2:成功，来自页面底部
function showMsg(strMsg,intMode,strURL)		
	select case intMode
	case 1
		response.Write("<p><div style='background-color:#ff0000; color:#ffffff; line-height:40px; width:200px; font-weight:bold; padding-left:10px;'>"&strMsg&"</div></p>")	
		response.Redirect(strURl)
	case 0
		response.Write("<p><div style='background-color:#ff0000; color:#ffffff; line-height:40px; width:200px; font-weight:bold; padding-left:10px;'>"&strMsg&"</div></p>")
		response.Write("<p><div style='background-color:#ff0000; color:#ffffff; line-height:40px; width:200px; font-weight:bold; padding-left:10px;'><a href='javascript:void(0)' onclick='history.back()'>点击这里</a>返回登录界面!</div></p>")
	case 2
		response.Write("<p><div style='background-color:#ff0000; color:#ffffff; line-height:40px; width:200px; font-weight:bold; padding-left:10px;'>"&strMsg&"</div></p>")
		response.Write("<script language='javascript'>window.open('"&strURL&"','loginSuccess','',true);window.close();</script>")
	case 3
		response.Write("<script language='javascript'>alert('"&strMsg&"');</script>")
	case 4
		response.Write("<p><div style='background-color:#ff0000; color:#ffffff; line-height:40px; width:100%; font-weight:bold; padding-left:10px;'>"&strMsg&"</div></p>")
	case else
		response.Write("<p><div style='background-color:#ff0000; color:#ffffff; line-height:40px; width:200px; font-weight:bold; padding-left:10px;'>您的登录是非法的！<br />跳转中...</div></p>")
		response.Redirect("../")	
	end select
end function
'文本化HTML
Function RemoveHTML(strText) 
  Dim RegEx    
  Set RegEx = New RegExp
  RegEx.Pattern = "<[^>]*>"   
  RegEx.Global = True    
  RemoveHTML = RegEx.Replace(strText,"")
End Function
'截取摘要
function abstract(strHTML,intLen)
	dim strText		
	strText=RemoveHTML(strHTML)
	if len(strText) <= intLen-3 then
		abstract=strText
	else
		abstract=Mid(strText,1,intLen-3)&"..."
	end if
end function
'从编辑器内容获得图片地址
Function GetPic(strHTML)
Dim objRegExp,m,Matches,pa
Set objRegExp = New Regexp
pa="<img [^>]*src=""([^"">]+)""[^>]+>" 
objRegExp.IgnoreCase = True
objRegExp.Global = False
objRegExp.Pattern = pa
Set Matches = objRegExp.Execute(strHTML)
If Matches.Count=1 Then
GetPic=Matches(0).submatches(0)
Else
GetPic=""
End If
End Function
'登出
function LogOut()
    do while IsLogin
        clearCookies()
    loop
    showMsg "退出成功",3,""
end function
%>
<script language="javascript" src="../skin/default/js/base.js" type="text/javascript"></script>